import matplotlib.pyplot as plt
import numpy as np

# 图像数据 二维数组形式显示像素值
def circle(x0,y0, r):
    # 坐标
    img = np.zeros((200,200))
    x1 = int(x0+r/2**0.5)+1
    xy= lambda x,y:[(      x,      y),(      x, 2*y0-y),
                    ( 2*x0-x,      y),( 2*x0-x, 2*y0-y),
                    (x0-y0+y,y0-x0+x),(x0-y0+y,y0+x0-x),
                    (x0+y0-y,y0-x0+x),(x0+y0-y,y0+x0-x)]
    for x in range(x0,x1):
        y = y0+int((r**2-(x-x0)**2)**0.5)
        for xp,yp in xy(x, y):
            img[200-xp-1,yp] = 255
    return img

img = circle(100,100, 50)

# 保存图像
plt.imsave("圆.png", img, cmap='gray_r')

# 显示图像
fig=plt.figure()
ax = fig.add_subplot(111)
ax.imshow(img, cmap='gray_r')
plt.show()